﻿using LoveEat.API.Write.Applications.Commands.Paths;
using LoveEat.Domain;
using LoveEat.ErrorCode;
using LoveEat.Infrastructure.Interfaces;
using MediatR;
using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal;

namespace LoveEat.API.Write.Applications.CommandHandlers.Paths
{
    public class PathAddCommandHandler : IRequestHandler<PathAddCommand, APIResult<int>>
    {
        private readonly IBaseRespository<PathModel> pathRep;

        public PathAddCommandHandler(IBaseRespository<PathModel> pathRep)
        {
            this.pathRep = pathRep;
        }

        public async Task<APIResult<int>> Handle(PathAddCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code=APIResultCode.添加成功;
            result.Message=APIResultCode.添加成功.ToString();

            PathModel path=new PathModel();
            path.PathType = request.PathType;
            path.RelateId=request.RelateId;
            path.PathName=request.PathName;
            path.PathUrl=request.PathUrl;

            await pathRep.AddAsync(path);


            return await Task.FromResult(result);
        }
    }
}
